package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;

import java.util.Map;

public class PanelQRBingingAdapter extends AppAdapter<Map> {
    public PanelQRBingingAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public PanelQRBingingAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PanelQRBingingAdapter.ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView keyName;
        private final TextView bingingName;
        private final TextView bingingState;

        private ViewHolder() {
            super(R.layout.panel_qr_binging_item);
            keyName = findViewById(R.id.key_name);
            bingingName = findViewById(R.id.binging_name);
            bingingState = findViewById(R.id.binging_state);
        }

        @Override
        public void onBindView(int position) {
            Map map = getItem(position);
            keyName.setText(map.get("name").toString());
            bingingName.setText(map.get("info").toString());
            if(map.get("bingingState") == null){
                bingingState.setText("");
            }else if(map.get("bingingState").equals(0)){
                bingingState.setText("失败");
            }else if(map.get("bingingState").equals(1)){
                bingingState.setText("成功");
            }else if(map.get("bingingState").equals(2)){
                bingingState.setText("绑定中");
            }else{
                bingingState.setText("");
            }
        }
    }
}
